package org.bet.domain;

import java.io.Serializable;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.Assert;

public abstract class AbstractIDAssignedObject implements Serializable {
	
	private static final long serialVersionUID = 7419731878392114535L;
	
	@Id
	private String id;
	AbstractIDAssignedObject(){}
	public AbstractIDAssignedObject(String id) {
		Assert.hasText(id, "id should be not empty");
		
		this.id = id;
	}

	public String getId() {
		return this.id;
	}

	public int hashCode() {
		return (id != null)? id.hashCode() : System.identityHashCode(this);
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || !(obj instanceof AbstractIDAssignedObject)){
			return false;
		}
		
		final AbstractIDAssignedObject other = (AbstractIDAssignedObject) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}